package cn.stylefeng.guns.modular.gridsystem.temperature.listener;


import cn.hutool.core.thread.ThreadUtil;
import cn.stylefeng.guns.modular.gridsystem.enums.temp.TempConfigUtil;
import cn.stylefeng.guns.modular.gridsystem.enums.temp.TempDictType;
import cn.stylefeng.guns.modular.gridsystem.websocket.WebSocketGatewayServer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class TemperatureListener implements CommandLineRunner {
    //CommandLineRunner是Spring Boot提供的一个便捷接口，它允许开发者在Spring应用程序启动后执行一些特定的代码。这个接口特别适用于那些需要在服务器启动时立即执行的任务，比如数据初始化、发送通知或者执行一些定时任务。
    @Autowired
    private WebSocketGatewayServer webSocketGatewayServer;

    @Autowired
    private TempConfigUtil tempConfigUtil;

    @Override
    public void run(String... args) throws Exception {
//        String recordIntervalStr = tempConfigUtil.getValue(TempDictType.TEMP_RECORD_INTERVAL);
//        String recordIntervalStr = DictUtils.getDicValueString("temp_record_Interval", "采集端上报温度间隔");
        String recordIntervalStr = "15";
        //转成毫秒
        Integer recordInterval = Integer.parseInt(recordIntervalStr) * 1000;

      // ThreadUtil.schedule(null, webSocketGatewayServer::saveTemperatureData, recordInterval, recordInterval, true);

//        log.info(">>>>>>" + "温度初始化定时任务启动成功！");
    }
}
